<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增转移任务')" />
    <th:block th:include="include :: summernote-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: datetimepicker-js" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-task1-transfer-add">
        <div class="col-md-12">
            <div class="form-group">
                <label class="col-sm-2 control-label">转移任务：</label>
                <div class="col-sm-3">
                    <select class="form-control" name="task_id" id="task_id">
                        <option value="">请选择</option>
                    </select>
                </div>
                <div class="col-sm-3">
                    <select class="form-control" name="applicant" id="applicant" required>
                        <option value="">请选择申请人</option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">申请时间：</label>
                <div class="col-sm-9">
                    <input type="text" class="input-sm form-control" id="datetimepicker-satartTime" name="applicantion_time"  placeholder="申请时间" readonly>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-2 control-label">申请原因：</label>
                <div class="col-sm-9">
                    <textarea type="text" style="height: 200px" name="transfer_reason" id="delayReason" class="form-control" placeholder="请输入申请原因" required maxlength="255"></textarea>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: summernote-js" />
<th:block th:include="include :: bootstrap-select-js" />
<th:block th:include="include :: datetimepicker-js" />
<script type="text/javascript">
    var prefix = ctx + "management/transfer";
    $("#datetimepicker-startTime").datetimepicker();
    $("#datetimepicker-satartTime").datetimepicker();

    /*$("#form-task1-transfer-add").validate({
        rules:{
            onkeyup: false,
            task_id:{
                remote: {
                    url: ctx + "management/delay/checkDelayTaskIdUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "task_id" : function() {
                            return $.common.trim($("#taskId").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                },
                digits:true
            }
        },
        messages: {
            "task_id": {
                remote: "该任务不存在或已是延期任务"
            },
        },
        focusCleanup: true
    });*/

    function getApplicant() {
        $.ajax({
            url: "/management/taskrw/selectAll2",
            type:"post",
            success: function (result) {
                $.each(result, function (index, value) {
                    var name = value.task_title;
                    var id = value.task_id;
                    $('#task_id').append("<option value='" + id + "'>" + name + "</option>");
                });
                $("#task_id").selectpicker('refresh');
            }
        });

        /*$("#comp").bind("change", function() {
            //刷新选中第一条空数据
            document.getElementById("dept").options.selectedIndex = 0;
            document.getElementById("applicant").options.selectedIndex = 0;
            //只保留下拉框中第一条空数据
            document.getElementById("dept").options.length = 1;
            document.getElementById("applicant").options.length = 1;
            $("#applicant").selectpicker('refresh');
            var deptId = $(this).val(); //获取当前下拉框name属性的值
            console.log(deptId);
            $.ajax({
                type : "POST",
                url : "/system/dept/selectDeptAll",
                data : {
                    "deptId" : deptId
                },
                success : function(result) {
                    $.each(result, function (index, value) {
                        var name = value.deptName;
                        var id = value.deptId;
                        $('#dept').append("<option value='" + id + "'>" + name + "</option>");
                    });
                    $("#dept").selectpicker('refresh');
                },
            });
        });*/




        $("#task_id").bind("change", function() {
            //刷新选中第一条空数据
            document.getElementById("applicant").options.selectedIndex = 0;
            //只保留下拉框中第一条空数据
            document.getElementById("applicant").options.length = 1;
            var task_id = $(this).val(); //获取当前下拉框name属性的值
            console.log(task_id);
            $.ajax({
                type : "post",

                url : "/management/taskrw/selectTaskAll",
                data : {
                    "task_id" : task_id
                },
                success : function(result) {
                    $.each(result, function (index, value) {
                        var name = value.user_name;
                        var id = value.executor;
                        $('#applicant').append("<option value='" + id + "'>" + name + "</option>");
                    });
                    $("#applicant").selectpicker('refresh');
                },
            });
        });
    }
    getApplicant();


    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add",$("#form-task1-transfer-add").serialize());
        }
    }

</script>
</body>
</html>
